import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_base_kit/net/dio_utils.dart';
import 'package:get/get.dart';

import '../global/sp_key.dart';
import '../home/home_main_page.dart';
import '../utils/sp_utils.dart';

class SplashController extends GetxController {
  @override
  void onInit() {
    if (Platform.isAndroid) {
      SystemChrome.setSystemUIOverlayStyle(
        const SystemUiOverlayStyle(statusBarColor: Colors.transparent),
      );
    }
    super.onInit();
  }

  @override
  void onReady() {
    super.onReady();
    requestNet();
  }

  LoadingStatues loadingStatues = LoadingStatues.loading;
  List<String> imageList = [
    "assets/images/sp03.png",
    "assets/images/sp03.png",
  ];

  Future<bool> requestNet() async {
    //网络请求
    await Future.delayed(Duration(seconds: 1), () {});
    //加载成功
    loadingStatues=LoadingStatues.success;
    update();
    return true;
  }

  String indexStr = "";
  bool showNext = false;

  void onPageChanged(int value) {
    indexStr = "第${(value + 1)}页";
    if (value == imageList.length - 1) {
      showNext = true;
    } else {
      showNext = false;
    }
    update();
  }

  void goHome() {
    //保存标识
    SPUtil.save(spUserIsFirstKey, true);
    //关闭当前页面 打开新的页面
    Get.off(() =>  HomeMainPage());
  }
}
